<template>
	<view>
		<form>
			<view class="cu-form-group margin-top">
				<view class="title">姓名</view>
				<input   v-model="returnName" placeholder="请输入退货人姓名" maxlength="10" name="input"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">手机号</view>
				<input   v-model="returnPhone" type="number" maxlength="11" placeholder="请输入退货人手机号" name="input"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">快递单号</view>
				<input  v-model="expressOrderCode"  placeholder="请输入退货快递单号" maxlength="30" name="input"></input>
			</view>
			<view class="cu-form-group align-start">
				<view class="title">退货原因</view>
				<textarea maxlength="150" @input="textareaInput" placeholder="请输入退货原因"></textarea>
			</view>
			<view class="padding">
				<button class="cu-btn block bg-blue margin-tb-sm lg" @click="orderReturn">提交申请</button>
			</view>
		</form>
	</view>
</template>

<script>
	
	export default {
		data() {
			return {
				orderGoodsId:"",
				reason:"",
				returnName:"",
				returnPhone:"",
				expressOrderCode:""
			}
		},
		onLoad(option){
			this.orderGoodsId = option.orderGoodsId;
		},
		methods: {
			textareaInput(e) {
				this.reason = e.detail.value
			},
			orderReturn:function(){
				if(!this.returnName){
					this.$api.msg("请输入姓名！");
					return;
				}
				if(!this.returnPhone || this.returnPhone.length != 11
					|| !/^1[34578]\d{9}$/.test(this.returnPhone)){
					this.$api.msg("请输入手机号！");
					return;
				}
				if(!this.reason){
					this.$api.msg("请输入退货原因！");
					return;
				}
				var that = this;
				var param = {
					userId:that.userInfo.id,
					orderGoodsId:that.orderGoodsId,
					reason:that.reason,
					returnName:that.returnName,
					returnPhone:that.returnPhone,
					expressOrderCode:that.expressOrderCode,
				}
				that.$api.req(param,"/orderReturn/save").then((res)=>{
					var d = res.data;
					if(d.success){
						uni.redirectTo({
							url:"return?state=1"
						})
					}
					that.$api.msg(d.msg);
				})
			},
		}
	}
</script>

<style>
	.cu-form-group .title {
		min-width: calc(4em + 15px);
	}
</style>
